package com.xoa.controller.hr;

import com.xoa.model.hr.*;
import com.xoa.service.hr.HrStaffLeaveService;
import com.xoa.util.ToJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 离职模块控制类
 */
@RestController
@RequestMapping("/hr/leave")
public class HrStaffLeaveController {

    @Autowired
    HrStaffLeaveService hrStaffLeaveService;

    /**
     * 创建作者：张丽军
     * 方法介绍：根据部门id查询离职人员信息
     * @param request
     * @param deptId
     * @return
     */
    @ResponseBody
    @RequestMapping("/getLeavePerson")
    public ToJson<HrStaffInfo> insertLeavePersonByDeptId(HttpServletRequest request, Integer deptId){
        return hrStaffLeaveService.querytLeavePersonByDeptId(request,deptId);
    }

    /**
     * 创建作者：张丽军
     * 方法介绍：根据部门Id查询离职人员名
     * @param request
     * @param deptId
     * @return
     */
    @ResponseBody
    @RequestMapping("/getLeaveUsersByDeptId")
    public ToJson<HrStaffLeave> getLeaveUsersByDeptId(HttpServletRequest request,Integer deptId){
        return hrStaffLeaveService.getLeaveUsersByDeptId(request,deptId);
    }

    /**
     * 创建作者：张丽军
     * 方法介绍：点击离职实现离职新建功能
     * @param hrStaffLeave
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/addLeaveInfor")
    public ToJson<HrStaffLeave> addLeaveInfor(HrStaffLeave hrStaffLeave,HttpServletRequest request){
        return hrStaffLeaveService.addLeaveInfor(hrStaffLeave,request);
    }

    /**
     * 创建作者：张丽军
     * 方法介绍：左侧部门树根据deptid查询人员
     * @param request
     * @param deptId
     * @return
     */
    @ResponseBody
    @RequestMapping("/getLeaveUserByDeptId")
    public ToJson<HrStaffLeave> getLeaveUserByDeptId(HttpServletRequest request,Integer deptId){
        return hrStaffLeaveService.getLeaveUserByDeptId(request,deptId);
    }

    /**
     * 郅浩宇 2018/7/29
     * 根据leaveId删除离职人员信息
     * @param leaveId
     * @return
     */
    @ResponseBody
    @RequestMapping("/leaveDelete")
    public ToJson<HrStaffLeave> deleteLeaveInfoByLeaveId(@RequestParam("leaveId[]") Integer[] leaveId){
        return hrStaffLeaveService.deleteLeaveInfoByLeaveId(leaveId);
    }

    /**
     * 郅浩宇 2018/7/29
     * 修改离职人员信息
     * @param hrStaffLeave
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/leaveUpdate")
    public ToJson<HrStaffLeave> updateByPrimaryKeySelective(HrStaffLeave hrStaffLeave,HttpServletRequest request){
        return hrStaffLeaveService.updateByPrimaryKeySelective(hrStaffLeave,request);
    }

    /**
     * 郅浩宇 2018/7/29
     * 复职
     * @param request
     * @param hrStaffLeave
     * @param reinstatementWithBLOBs
     * @return
     */
    @ResponseBody
    @RequestMapping("/leaveReinstatement")
    public ToJson<HrStaffLeave> leaveReinstatement(HttpServletRequest request,HrStaffLeave hrStaffLeave,HrStaffReinstatementWithBLOBs reinstatementWithBLOBs){
        return hrStaffLeaveService.leaveReinstatement(request,hrStaffLeave,reinstatementWithBLOBs);
    }

    /**
     * 郅浩宇 2018/7/30
     * 根据leaveId查询详细信息
     * @param leaveId
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/leaveDetails")
    public ToJson<HrStaffLeave> leaveDetails(Integer leaveId,HttpServletRequest request){
        return hrStaffLeaveService.leaveDetails(leaveId,request);
    }

    /**
     * 郅浩宇 2018/7/30
     * 查询黑名单，需要一定的权限
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/leaveBlackList")
    public ToJson<HrStaffLeave> leaveBlackList(HttpServletRequest request){
        return hrStaffLeaveService.leaveBlackList(request);
    }

    /**
     * 郅浩宇 2018/7/30
     * 查询本月离职人员信息
     * @return
     */
    @ResponseBody
    @RequestMapping("/leaveThisMonth")
    public ToJson<HrStaffLeave> leaveThisMonth(){
        return hrStaffLeaveService.leaveThisMonth();
    }

    /**
     * 郅浩宇 2018/7/31
     * 条件查询
     * @param leavePerson
     * @param quitType
     * @param deptId
     * @param quitTimePlanStart
     * @param quitTimePlanEnd
     * @param quitTimeFactStart
     * @param quitTimeFactEnd
     * @param quitReason
     * @param despacho
     * @param useFlag
     * @param pageSize
     * @param page
     * @return
     */
    @ResponseBody
    @RequestMapping("/leaveCondition")
    public ToJson<HrStaffLeave> leaveConditionQuery(String leavePerson,String quitType,String deptId,String quitTimePlanStart,String quitTimePlanEnd,String quitTimeFactStart,String quitTimeFactEnd,String quitReason,String despacho,Boolean useFlag,Integer pageSize,Integer page){
        return hrStaffLeaveService.leaveConditionQuery(leavePerson,quitType,deptId,quitTimePlanStart,quitTimePlanEnd,quitTimeFactStart,quitTimeFactEnd,quitReason,despacho,useFlag,pageSize,page);
    }

    /**
     * 郅浩宇
     * 列表查询
     * @param useFlag
     * @param pageSize
     * @param page
     * @return
     */
    @ResponseBody
    @RequestMapping("/leaveQuery")
    public ToJson<HrStaffLeave> leaveQuery(Boolean useFlag,Integer pageSize,Integer page,String leavePerson){
        return hrStaffLeaveService.leaveQuery(useFlag,pageSize,page,leavePerson);
    }

    /**
     * 郅浩宇 2018/7/30
     * 导入离职人员信息
     * @param file
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/leaveImport")
    public ToJson<HrStaffLeave> importLeaveInfo(MultipartFile file,HttpServletRequest request){
        return hrStaffLeaveService.importLeaveInfo(file,request);
    }

    /**
     * 郅浩宇2018/7/31
     * 导出离职人员信息
     * @param
     * @param response
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/leaveExport")
    public ToJson<HrStaffLeave> exportLeaveInfo(String leavePerson,String quitType,String deptId,String quitTimePlanStart,String quitTimePlanEnd,String quitTimeFactStart,String quitTimeFactEnd,String quitReason,String despacho,Boolean useFlag,Integer pageSize,Integer page, HttpServletResponse response, HttpServletRequest request) {

        return hrStaffLeaveService.exportLeaveInfo(leavePerson,quitType,deptId,quitTimePlanStart,quitTimePlanEnd,quitTimeFactStart,quitTimeFactEnd,quitReason,despacho,useFlag,pageSize,page,response,request);
    }

}
